﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fotobanka
{
    public partial class index : System.Web.UI.MasterPage
    {
        UserManager um;

        protected void Page_Load(object sender, EventArgs e)
        {
            um = new UserManager();
            LoginInfo li = (LoginInfo)Session["logged_user_id"];

            if (li != null) //je nekdo lognuty?
            {
                login_box.Visible = false;
                logout_box.Visible = true;
            }
        }

        protected void login_button_Click(object sender, EventArgs e)
        {
            LoginInfo li = um.LogIn(login.Text, pass.Text);

            if (li != null)
            {
                HttpContext.Current.Session.Timeout = 24 * 60;//prihlaseni na 24 hodin
                HttpContext.Current.Session["logged_user_id"] = li;
            }

            Response.Redirect("MemberArea.aspx", true);
        }

        protected void logout_button_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["logged_user_id"] = null;
            Response.Redirect("Default.aspx", true);
        }
    }
}
